//
//  YWMeterReadingManager.h
//  maintain
//
//  Created by 郑想 on 16/2/26.
//  Copyright © 2016年 ewin. All rights reserved.
//
#import "YWEquipment.h"
#import "YWMeterReadingRecord.h"
#import "YWPatrolPicture.h"
#import "YWSingleton.h"
#import <Foundation/Foundation.h>

@class YWEquipment;
static NSString *const KPostMaterReadingSuccessNotification = @"KPostMaterReadingSuccessNotification";
static NSString *const KModifyMeterReadSuccessNotification = @"KModifyMeterReadSuccessNotification";

typedef void (^YWNewestReadingCompleteBlock)(YWMeterReadingRecord* record);

@interface YWMeterReadingManager : NSObject
YWSingletonH(Manager)

-(NSInteger)waterMeterEquipmentTypeId;
-(NSInteger)electricMeterEquipmentTypeId;
-(NSInteger)gasMeterEquipmentTypeId;
    /**
 *  表号判断是不是可抄表的设备
 *
 *  @param ownCode 设备自编码 （表号）
 *
 *  @return nil 不能抄表
 */
    - (YWEquipment*)meterNumber : (NSString*)ownCode;
/**
 *  扫码判断是不是可抄表的设备
 *
 *  @param qrCode 二维码
 *
 *  @return nil 不能抄表
 */
- (YWEquipment*)meterQRCoder:(NSString*)qrCode;

- (void)requestNewestReadingMemterRecord:(NSString*)equipmentId complete:(YWNewestReadingCompleteBlock)block;

/**
 *  保存巡更图片
 *
 *  @param patrolPictures 巡更图片模型数组
 *
 *  @return 结果
 */
- (BOOL)updatePatrolPictureWithArray:(NSArray*)patrolPictures;
/**
 *  巡更记录图片或者抄表记录图片
 *
 *  @param recordId 记录Id
 *  @param recordType 图片的类型（巡更或者抄表）
 *
 *  @return 巡更图片模型数组
 */
- (NSArray*)recordPictureWithRecordId:(NSString*)recordId recordType:(YWPictureRecordType)recordType;
/**
 *  保存抄表记录
 *
 *  @param records 抄表记录模型数组
 *
 *  @return 结果
 */
- (BOOL)updateMeterReadingRecordWithRecordArray:(NSArray*)records;
/**
 *  保存抄表记录
 *
 *  @param record 抄表记录模型
 *
 *  @return 结果
 */
- (BOOL)updateMeterReadingRecordWithRecord:(YWMeterReadingRecord*)record;

/**
 *  (水，电，燃气)抄表记录
 *
 *  @param meterEquipmentType 设备类型
 *
 *  @return 结果
 */
- (NSArray*)meterReadingRecordWithEquipmentType:(NSInteger)meterEquipmentType page:(NSInteger)page;
/**
 *  (水，电，燃气)抄表记录
 *
 *  @param recordId 记录id
 *
 *  @return 结果
 */
- (YWMeterReadingRecord*)meterReadingRecordWithRecordId:(NSString*)recordId;
/**
 *  本地某设备最新一条抄表记录
 *
 *  @param equipmentId 设备id
 *
 *  @return 结果
 */
- (YWMeterReadingRecord*)latestMeterReadingRecordWithEquipmentId:(NSString*)equipmentId;
/**
 *  修改抄表记录的id
 *
 *  @param record 抄表记录模型
 *  @param recordId 抄表记录ID
 *
 *  @return 结果
 */
- (BOOL)modifyMeterReadingRecordIdWithRecord:(YWMeterReadingRecord*)record recordId:(NSString*)recordId;
/**
 *  更新抄表记录的上传状态
 *
 *  @param uploadStatus  上传状态
 *  @param recordId 记录id
 *
 *  @return 结果
 */
- (BOOL)updateMeterReadingRecordUploadStatus:(YWMeterReadingRecordUploadStatus)uploadStatus recordId:(NSString*)recordId;
/**
 *  删除抄表记录数据
 *
 *  @param meterEquipmentType 类型id
 *
 *  @return 结果
 */
- (BOOL)deleteMeterReadingRecordWithEquipmentType:(NSInteger)meterEquipmentType;

/**
 *  获取上传失败的抄表记录
 *
 *  @return 抄表模型数组
 */
- (NSArray*)meterReadingRecordWithUploadStatusFail;
/**
 *  开始后台上传任务
 *  @param records        记录模型数组
 *  @param pictures       记录中所有的图片数组
 */
- (void)startUploadMeterReadingRecords:(NSArray*)records pictures:(NSArray*)pictures;
/**
 *  上传失败的抄表记录
 *
 *  @return 抄表记录模型数组
 */
- (void)uploadFailMeterReadingRecords;
/**
 *  修改图片的关联ID
 *
 *  params recordId
 */
- (BOOL)updatePatrolPictureRecordId:(NSString*)recordId WithOldRecordId:(NSString*)ordRecordId;

/**
 *  获取所有楼盘当月已抄表数量
 *
 *  @param equipmenttypeId 仪表类型Id
 *
 *  @return  数组
 
 */
- (NSArray*)allThisMonthReadMeterCount:(NSInteger)equipmenttypeId;
- (void)requestThisMonthReadingMeterCount:(void (^)(BOOL success))complete;
/**
 *  请求我的抄表记录
 *
 *  @return 无
 */
-(void)requestMyMeterReadingRecordsWithEquipmentTypeOwnCode:(NSString*)equipmentTypeOwnCode page:(NSInteger)page pageSize:(NSInteger)pageSize Block:(void (^)(BOOL success))complete;
/**
 *  获取今天的抄表数
 *
 *  @param equipmentTypeId 设备类型Id
 *
 *  @return 数量
 */
- (NSInteger)toDayReadMeterCountWithEquipmentTypeId:(NSInteger)equipmentTypeId;

- (void)modifyThisReadNumberOfMeterReadingRecord:(YWMeterReadingRecord*)record withBlock:(void (^)(BOOL success))complete;
/**
 *  请求查询待抄的表
 *
 *  @return 结果
 */
- (void)requestUnReadMeterArrayWithPage:(NSInteger)page equipmentTypeCode:(NSString*)equipmentTypeCode buildingId:(NSString*)buildingId apartmentId:(NSInteger)apartmentId floorId:(NSInteger)floorId locationId:(NSInteger)locationId meterChargeTypeId:(NSInteger)chargeTypeId complete:(void (^)(NSArray *meterArray))complete;
/**
 *  请求查询已抄的表
 *
 *  @return 结果
 */
- (void)requestHaveReadMeterArrayWithPage:(NSInteger)page equipmentTypeCode:(NSString*)equipmentTypeCode buildingId:(NSString*)buildingId apartmentId:(NSInteger)apartmentId floorId:(NSInteger)floorId locationId:(NSInteger)locationId meterChargeTypeId:(NSInteger)chargeTypeId complete:(void (^)(NSArray *meterArray))complete;
@end
